package com.situ.mall.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.common.util.PageResult;
import com.situ.mall.mapper.*;
import com.situ.mall.pojo.entity.User;
import com.situ.mall.pojo.query.UserQuery;
import com.situ.mall.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private CartMapper cartMapper;
    @Autowired
    private CollectMapper collectMapper;
    @Autowired
    private CouponMapper couponMapper;
    @Autowired
    private DrawMapper drawMapper;
    @Autowired
    private EvaluateMapper evaluateMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private OrderItemMapper orderItemMapper;
    @Autowired
    private ShippingMapper shippingMapper;


    @Override
    public PageResult list(UserQuery userQuery) {
        PageHelper.startPage(userQuery.getPage(), userQuery.getLimit());
        List<User> list = userMapper.list(userQuery);
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();
        return PageResult.ok(totalCount, list);
    }

    @Override
    public void update(User user) {
        userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public void add(User user) {
        userMapper.insertSelective(user);
    }

    @Override
    public Integer selectByAccount(User user) {
        return userMapper.selectByAccount(user);
    }

    @Override
    public User selectById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer selectByAccountId(User user) {
        return userMapper.selectByAccountId(user);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        userMapper.deleteAll(ids);
    }

    @Override
    public void deleteById(Integer id) {
        userMapper.deleteByPrimaryKey(id);
        cartMapper.deleteById(id);
        collectMapper.deleteById(id);
        couponMapper.deleteById(id);
        drawMapper.deleteById(id);
        evaluateMapper.deleteById(id);
        orderMapper.deleteById(id);
        orderItemMapper.deleteById(id);
        shippingMapper.deleteById(id);
    }

    @Override
    public Integer totalCost() {
        return userMapper.totalCost();
    }

    @Override
    public Integer totalCostEvaluate() {
        return evaluateMapper.totalCost();
    }
}
